package com.register.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.register.dao.QRDepotMapper;
import com.register.pojo.QRDepot;
import com.register.service.QRDepotService;
import com.register.util.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class QRDepotServiceImpl extends ServiceImpl<QRDepotMapper, QRDepot> implements QRDepotService {

    @Resource
    QRDepotMapper qrDepotMapper;
    @Override
    public List getDepotById(Long id) {

        return qrDepotMapper.getDepotById(id);
    }

    public Result add(QRDepot qrDepot){

        //判断场站有没有重名的情况
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("name",qrDepot.getName());
        int count = qrDepotMapper.selectCount(wrapper);
        if (count>0){
            return Result.build(1,"场站名重复");
        }else {
            qrDepotMapper.insert(qrDepot);
            return Result.ok();
        }
    }

}
